//#define BOOST_SPIRIT_DEBUG

#include <ace/OS.h>

#include "pkdata.h"
#include "simplesynax.h"

#include <cstdio>
#include <cstdlib>

#include <ace/Log_Msg.h>
#include <fstream>
#include <iostream>


//#ifdef _WIN32
//#ifdef	_DLL_EXPORTER
//#define DLLEXPORTER __declspec(dllexport)
//#else
//#define DLLEXPORTER __declspec(dllimport)
//#endif
//#else
//#define DLLEXPORTER
//#endif
//
//extern "C"
//{
//	DLLEXPORTER int producer( unsigned char *outbuffer );
//}
//
//int producer()
//{
//	return 0;
//}

/*! in this form, skipper works ,such as `space_p`.*/

/*struct sp_delcare : public grammar< sp_delcare >
{
	template< typename ScannerT >
	struct definition
	{
		definition( sp_delcare const & self )
		{
			nondigit_			= alpha_p|ch_p('_');
			identifier_			= nondigit_>>*( nondigit_ | digit_p );
			simple_declare_		=  identifier_ & space_p >>  identifier_;
		}
		rule< ScannerT > nondigit_, identifier_, simple_declare_;
		rule< ScannerT > const & start() { return simple_declare_ ; }
	};
};*/

const char *_struct = "struct _tag_tester{\
					  int val1;\
					  double dbval;\
					  };";
const char *_statement	= "int val;";
const char *_class_head = "struct _tag_tester{";
const char *_block		= "{int val;double dbval;}";
const char *_sp_delcare = "int val";
const char *_id = " int ";
struct Mytst{
	char _ch;
	int _c;
	long long _shrt;
	int _val;
};

int ACE_TMAIN( int , char ** )
{
	Mytst _tst;
	/*_tst._ch = 1;
	_tst._shrt = 2;
	_tst._c = 3;
	*/
	int _len = sizeof( Mytst );

	const int TEST_LEN = 4;
	int _seq[TEST_LEN] = { 1, 1, 1, 1 };
	int _type[TEST_LEN] = { 1, 4, 8, 4 };
	int _total = 0;
	unsigned char _buffer[8192] = {0};
	int _pos = 0;
	int _typemax = 0;
	int _mod = 0;
	for( int i = 0, _pre = 0; i < TEST_LEN; ++i )
	{
		_mod = _pos % _type[i];
		if( _mod != 0 )
		{
			int _fix = _type[i] - _mod;
			_pos = _pos + _fix;
		}
		memset( _buffer + _pos, i, 1 );
		_pos += _type[i]*_seq[i];

		if( _type[i] > _typemax	)
			_typemax = _type[i];
	}
	_mod = _pos % _typemax;
	_pos += _mod;
	return 0;
}

int random_value( unsigned char buffer, int &pos, int type, int count )
{
	return 0;
}